import 'package:get/get.dart';
import 'package:safemap/safemap.dart';

class AfterSalePluginBackModel {
  Rxn<List> errorList = Rxn();
  String url = "";
  String code = "";
}

class DiagnosisModel {
  String code = "";
  String result = "";
  String url = "";
  Rxn<List<DiagnosisDescriptionModel>> descriptions = Rxn();

  // map 转模型
  DiagnosisModel.fromMap(Map<dynamic, dynamic> map) {
    SafeMap data = SafeMap(map);
    code = data["code"].string ?? "";
    result = data["result"].string ?? "";
    url = data["url"].string ?? "";
    var list = data['description'].list;
    if (list != null) {
      descriptions.value =
          list.map((e) => DiagnosisDescriptionModel.fromMap(e)).toList();
    }
  }

  // 模型转json
  Map<String, dynamic> toMap() {
    Map<String, dynamic> map = Map.from({});
    map["code"] = code;
    map["result"] = result;
    map["url"] = url;
    map["description"] = descriptions.value?.map((e) => e.toMap()).toList();
    return map;
  }
}

class DiagnosisDescriptionModel {
  String category = "";
  List warnings = [];
  List errors = [];

  // map 转模型
  DiagnosisDescriptionModel.fromMap(Map<dynamic, dynamic> map) {
    SafeMap data = SafeMap(map);
    category = data["category"].string ?? "";
    var wlist = data['warnings'].list;
    if (wlist != null) {
      warnings = wlist.map((e) => e as String).toList();
    }

    var elist = data['errors'].list;
    if (elist != null) {
      errors = elist.map((e) => e as String).toList();
    }
  }

  // 模型转json
  Map<String, dynamic> toMap() {
    Map<String, dynamic> map = Map.from({});
    map["category"] = category;
    map["warnings"] = warnings;
    map["errors"] = errors;
    return map;
  }
}
